#ifndef _UNDO_H
#define _UNDO_H

#include "buffer.h"
#include "list.h"

#define UNDO_OK 1
#define UNDO_FAIL -1

struct undo_cmd;
typedef struct undo_cmd undo_cmd_t;

typedef void (*action)(undo_cmd_t *);

struct undo_cmd {
    action exec;
    buf_t *buf;
    char *data;
    int start;
    int end;
    int left;
    struct list_head list;
};

extern const action BUF_APPENDS_ACTION;
extern const action BUF_APPENDC_ACTION;
extern const action BUF_INSERTS_ACTION;
extern const action BUF_INSERTC_ACTION;
extern const action BUF_DELETE_ACTION;
extern const action BUF_REPLACE_ACTION;
extern const action BUF_RESTORE_BUF_ACTION;
extern const action BUF_DELETE_BUF_ACTION;
extern const action BUF_REMOVE_BUF_ACTION;

void undo_cmd_add(action act, buf_t *buf, char *data, 
		  int start, int end, int left);
int undo(void);
int redo(void);
void undo_cmd_clear_cmds(undo_cmd_t *cmd_head);
#endif /* _UNDO_H */
